<!DOCTYPE html>
<html>
<head lang="en">
    <title>您搜索的内容是:</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/strategy.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/common.js"></script>
</head>
<script>
    $(function () {
        var params = getParams();
        var keyword = decodeURIComponent(params.keyword);
        var type1 = params.type;
        $(".search p").html("您搜索的内容是:" + keyword);

        $.get(baseUrl + "searchs/count?keyword="+keyword, function (data) {
            if (!type1) {
                if (data.strategyCount != 0) {
                    $("#strategy").trigger("click");
                }
                $("#strategy span").html("攻略[" + data.strategyCount + "]");
                if (data.strategyCount == 0 & data.travelCount != 0) {
                    $("#travel").trigger("click");
                }
                $("#travel span").html("游记[" + data.travelCount + "]");
                if (data.strategyCount == 0 & data.travelCount == 0) {
                    $("#newsPage").trigger("click");
                }
                $("#newsPage span").html("日报[" + data.newsPageCount + "]");
            } else {
                if (type1 == 1) {
                    console.log(1);
                    $("#strategy span").html("攻略[" + data.strategyCount + "]");
                    $("#strategy").trigger("click");
                }
                if (type1 == 2) {
                    $("#travel").trigger("click");
                    $("#travel span").html("游记[" + data.travelCount + "]");
                }
                if (type1 == 3) {
                    $("#newsPage").trigger("click");
                    $("#newsPage span").html("日报[" + data.newsPageCount + "]");
                }
            }
        });


        var type;
        var pages = 2;//总页数
        $(".clickTab").click(function () {
            $(".fade").html("")
            type = $(this).data("type");
            $.get(baseUrl +"/searchs", {keyword: keyword, currentPage: 1, type: type}, function (data) {
                if (type == 1) {
                    if (data.total != 0) {
                        var temp = "";
                        $.each(data.list, function (index, ele) {
                            temp += "<div>\n" +
                                "            <div class=\"container commend\">\n" +
                                "                <a href=\"strategyDetails.html?id=" + ele.id + "\">\n" +
                                "                    <p>" + ele.title + "</p>\n" +
                                "                    <img src=" + ele.coverUrl + ">\n" +
                                "                </a>\n" +
                                "            </div>\n" +
                                "&nbsp;&nbsp;&nbsp;<span>" + ele.releaseTime +
                                "&nbsp;&nbsp;&nbsp;<i class='fa fa-eye handleBtn' id='likeBtn'>" + ele.browseNum + "</i></span>"
                            "            <hr>\n" +
                            "        </div>"
                        })
                        $("#pills-strategy").append(temp);
                    } else {
                        $("#pills-strategy").html("您搜索的攻略内容不存在");
                    }
                }
                if (type == 2) {
                    if (data.total != 0) {
                        var temp = "";
                        $.each(data.list, function (index, ele) {
                            temp += "<div>\n" +
                                "            <div class=\"container commend\">\n" +
                                "                <a href=\"travelContent.html?id=" + ele.id + "\">\n" +
                                "                    <p>" + ele.title + "</p>\n" +
                                "                    <img src=" + ele.coverUrl + ">\n" +
                                "                </a>\n" +
                                "            </div>\n" +
                                "&nbsp;&nbsp;&nbsp;<span>"+ ele.author.nickName+"&nbsp;&nbsp;&nbsp;"+ ele.lastUpdateTime +
                                "&nbsp;&nbsp;&nbsp;<i class='fa fa-eye handleBtn'>" + ele.browseNum + "</i></span>"
                            "            <hr>\n" +
                            "        </div>"
                        })
                        $("#pills-travel").append(temp);
                    } else {
                        $("#pills-travel").html("您搜索的游记内容不存在");
                    }
                }
                if (type == 3) {
                    if (data.total != 0) {
                        var temp = "";
                        $.each(data.list, function (index, ele) {
                            temp += "<div>\n" +
                                "            <div class=\"container commend\">\n" +
                                "                <a href=\"newsContent.html?id=" + ele.id + "\">\n" +
                                "                    <p>" + ele.title + "</p>\n" +
                                "                    <img src=" + ele.coverUrl + ">\n" +
                                "                </a>\n" +
                                "            </div>\n" +
                                "&nbsp;&nbsp;&nbsp;<span>" + ele.releaseTime +
                                "&nbsp;&nbsp;&nbsp;<i class='fa fa-eye handleBtn' id='likeBtn'>" + ele.browseNum + "</i></span>"
                            "            <hr>\n" +
                            "        </div>"
                        })
                        $("#pills-newsPage").append(temp);
                    } else {
                        $("#pills-newsPage").append("您搜索的内容不存在");
                    }
                }
                pages = data.pages;
            });
            currentPage = 2;//重置分页参数
        })

        var currentPage = 2;//当前页
        //搜索攻略
        function query() {
            $.get(baseUrl +"/searchs", {
                keyword: keyword,
                currentPage: currentPage,
                type: type
            }, function (data) {
                if (type == 1) {
                    var temp = "";
                    $.each(data.list, function (index, ele) {
                        temp += "<div>\n" +
                            "            <div class=\"container commend\">\n" +
                            "                <a href=\"strategyDetails.html?id=" + ele.id + "\">\n" +
                            "                    <p>" + ele.title + "</p>\n" +
                            "                    <img src=" + ele.coverUrl + ">\n" +
                            "                </a>\n" +
                            "            </div>\n" +
                            "&nbsp;&nbsp;&nbsp;<span>" + ele.releaseTime +
                            "&nbsp;&nbsp;&nbsp;<i class='fa fa-eye handleBtn' id='likeBtn'>" + ele.browseNum + "</i></span>"
                        "            <hr>\n" +
                        "        </div>"
                    })
                    $("#pills-strategy").append(temp);
                    pages = data.pages;
                }
                if (type == 2) {
                    var temp = "";
                    $.each(data.list, function (index, ele) {
                        temp += "<div>\n" +
                            "            <div class=\"container commend\">\n" +
                            "                <a href=\"travelContent.html?id=" + ele.id + "\">\n" +
                            "                    <p>" + ele.title + "</p>\n" +
                            "                    <img src=" + ele.coverUrl + ">\n" +
                            "                </a>\n" +
                            "            </div>\n" +
                            "&nbsp;&nbsp;&nbsp;<span>" + ele.author.nickName+"&nbsp;&nbsp;&nbsp;"+ ele.lastUpdateTime +
                            "&nbsp;&nbsp;&nbsp;<i class='fa fa-eye handleBtn'>" + ele.browseNum + "</i></span>"
                        "            <hr>\n" +
                        "        </div>"
                    })
                    $("#pills-travel").append(temp);
                    pages = data.pages;
                }
                if (type == 3) {
                    var temp = "";
                    $.each(data.list, function (index, ele) {
                        temp += "<div>\n" +
                            "            <div class=\"container commend\">\n" +
                            "                <a href=\"newsContent.html?id=" + ele.id + "\">\n" +
                            "                    <p>" + ele.title + "</p>\n" +
                            "                    <img src=" + ele.coverUrl + ">\n" +
                            "                </a>\n" +
                            "            </div>\n" +
                            "&nbsp;&nbsp;&nbsp;<span>" + ele.releaseTime +
                            "&nbsp;&nbsp;&nbsp;<i class='fa fa-eye handleBtn' id='likeBtn'>" + ele.browseNum + "</i></span>"
                        "            <hr>\n" +
                        "        </div>"
                    })
                    $("#pills-newsPage").append(temp);
                    pages = data.pages;
                }
            })
            currentPage++;
        }

        //监听滚动事件
        $(window).scroll(function () {
            if (($(document).scrollTop() + $(window).height()) >= $(document).height() - 1) {
                if (currentPage <= pages) {
                    query();
                } else {
                    $(document).dialog({
                        type: 'notice',
                        infoText: '亲,在拉就出翔了!',
                        autoClose: 1000,
                        position: 'bottom'  // center: 居中; bottom: 底部
                    });
                }
            }
        });
    });
</script>
<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="javascript:history.go(-1);">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div class="col-10">
            <div class="input-group-sm search">
                <p style="color: white; font-size: 20px"></p>
            </div>
        </div>
    </div>
</div>

<ul class="nav nav-pills nav-justified border border-left-0 border-top-0 border-right-0"
    id="pills-tab" role="tablist">
    <li class="nav-item" style="width: 33%">
        <a role="button" id="strategy" class="nav-link clickTab active show" data-type="1"
           data-toggle="pill"
           href="#pills-strategy">
            <span class="strategy"></span>
        </a>
    </li>
    <li class="nav-item" style="width: 33%">
        <a role="button" id="travel" class="nav-link clickTab" data-type="2" data-toggle="pill"
           href="#pills-travel">
            <span class="travel"></span>
        </a>
    </li>
    <li class="nav-item" style="width: 33%">
        <a role="button" id="newsPage" class="nav-link clickTab" data-type="3" data-toggle="pill"
           href="#pills-newsPage">
            <span class="newsPage"></span>
        </a>
    </li>

</ul>
<div class="tab-content" id="pills-tabContent">
    <div class="tab-pane fade active show" id="pills-strategy">
        <!--<div render-loop="list">
            <div class="container commend">
                <a data-href="strategyDetails.html?id=" render-fun="getHref" render-key="list.id">
                    <p render-html="list.title"></p>
                    <img render-src="list.coverUrl">
                </a>
            </div>
            <hr>
        </div>-->
    </div>
    <div class="tab-pane fade" id="pills-travel">
        <!--<div render-loop="list">
            <div class="container commend">
                <a data-href="travelContent.html?id=" render-fun="getHref" render-key="list.id">
                    <p render-html="list.title"></p>
                    <img render-src="list.coverUrl">
                </a>
            </div>
            <hr>
        </div>-->
    </div>
    <div class="tab-pane fade" id="pills-newsPage">
        <!--<div render-loop="list">
            <div class="container commend">
                <a data-href="newsContent.html?id=" render-fun="getHref" render-key="list.id">
                    <p render-html="list.title"></p>
                    <img render-src="list.coverUrl">
                </a>
            </div>
            <hr>
        </div>-->
    </div>
</div>
</body>
</html>